package org.jmh.gift.rocketmq.listener;

import org.jmh.gift.contants.SysConstants;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * 消息监听器
 *  延迟做第二次缓存删除
 */
@Component
@RocketMQMessageListener(topic = SysConstants.TENANT_TYPE_DELAY_DOUBLE_DEL_TX_TOPIC,
        consumerGroup = SysConstants.TENANT_TYPE_DELAY_DOUBLE_DEL_TX_CONSUMER_GROUP)
public class TenantTypeDelayDoubleDelMessageListener implements RocketMQListener<MessageExt> {

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void onMessage(MessageExt message) {
        try {
            // 睡眠一会儿
            Thread.sleep(3000);
            // 第二次删除缓存
            redisTemplate.delete("tenant_type_redis_key");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
